home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 7 / Apprentice-Release7.iso / Source Code / Libraries / SAT 2.4.0 / SAT / Add-ons / Load faces / FaceFromText.p < prev    next >
Encoding:
Text File  |  1997-03-12  |  2.4 KB  |  107 lines  |  [TEXT/PJMM]

  1. {Rutin för att skapa text-faces för SAT. Skall användas i Drömspelet, för scrollande deltagarlista.}
  2.  
  3. {A procedure for creating a face from a string. It uses the font, size and color from the current port.}
  4.  
  5. unit FaceFromText;
  6. interface
  7.     uses
  8. {$IFC UNDEFINED THINK_PASCAL}
  9.         Types, QuickDraw, Memory, Resources, ToolUtils, Fonts, QuickDrawText,
  10. {$ENDC}
  11.         SAT;
  12.  
  13.     function FaceFromText (myString: Str255; shadow: Integer): FacePtr;
  14.  
  15. implementation
  16.  
  17.     function FaceFromText (myString: Str255; shadow: Integer): FacePtr;
  18.         var
  19.             theTextFace: FacePtr;
  20.             r: Rect;
  21.             height, width: Integer;
  22.         var
  23.             info: FontInfo;
  24.             txFont: INTEGER;
  25.             txFace: Style;
  26.             txSize: INTEGER;
  27.             txColor: RGBColor;
  28.             txColor2: Longint;
  29.             savePort: SATPort;
  30.     begin
  31.         SATGetPort(savePort);
  32. {Get font etc from the current port.}
  33.         GetFontInfo(info);
  34.         width := StringWidth(myString) + shadow;
  35.         height := info.ascent + info.descent + shadow;
  36.  
  37. {$IFC UNDEFINED THINK_PASCAL}
  38.         txFont := qd.thePort^.txFont;
  39.         txSize := qd.thePort^.txSize;
  40.         txFace := qd.thePort^.txFace;
  41. {$ELSEC}
  42.         txFont := thePort^.txFont;
  43.         txSize := thePort^.txSize;
  44.         txFace := thePort^.txFace;
  45. {$ENDC}
  46.  
  47.         if gSAT.colorFlag then
  48.             GetForeColor(txColor)
  49.         else
  50. {$IFC UNDEFINED THINK_PASCAL}
  51.             txColor2 := qd.thePort^.fgColor;
  52. {$ELSEC}
  53.             txColor2 := thePort^.fgColor;
  54. {$ENDC}
  55.  
  56. {Create the face}
  57.         SetRect(r, 0, 0, width, height);{}
  58.         theTextFace := SATNewFace(r);
  59.  
  60.         SATSetPortFace(theTextFace);
  61. {Set up the face-port with the parameters we got above}
  62.         TextFont(txFont);
  63.         TextSize(txSize);
  64.         TextFace(txFace);
  65.  
  66.         if gSAT.colorFlag then
  67.             RGBForeColor(txColor)
  68.         else
  69.             ForeColor(txColor2);
  70.  
  71.         EraseRect(theTextFace^.iconMask.bounds);
  72. {Draw shadow, if any}
  73.         if shadow <> 0 then
  74.             begin
  75.                 MoveTo(shadow, info.ascent + shadow);
  76.                 ForeColor(blackColor);
  77.                 DrawString(myString);
  78.             end;
  79. {Draw text}
  80.         if gSAT.colorFlag then
  81.             RGBForeColor(txColor)
  82.         else
  83.             ForeColor(txColor2);
  84.         MoveTo(0, info.ascent);
  85.         DrawString(myString);
  86. {Set the forecolor to black before leaving!}
  87.         ForeColor(blackColor);
  88. {Draw the mask!}
  89.         SATSetPortMask(theTextFace);
  90.         TextFont(txFont);
  91.         TextSize(txSize);
  92.         TextFace(txFace);
  93.         EraseRect(theTextFace^.iconMask.bounds);
  94.         MoveTo(0, info.ascent);
  95.         DrawString(myString);
  96.         if shadow <> 0 then
  97.             begin
  98.                 MoveTo(shadow, info.ascent + shadow);
  99.                 DrawString(myString);
  100.             end;
  101. {Set back the port!}
  102.         SATSetPort(savePort);
  103.         SATChangedFace(theTextFace);
  104.         FaceFromText := theTextFace;
  105.     end;
  106.  
  107. end.